import java.util.Stack;

public class Text {
    //    给定一个只包括 '('，')'，'{'，'}'，'['，']' 的字符串 s ，判断字符串是否有效。
    public boolean isValid(String s) {
        Stack<Character> stack = new Stack<>();
        for (int i = 0; i < s.length(); i++) {
            char ch1 = s.charAt(i);
            if (ch1 == '(' || ch1 == '{' || ch1 == '[') {
                stack.push(ch1);
            } else {
                if (stack.empty()) {
                    return false;
                }
                char ch2 = stack.peek();
                if (ch2 == '(' && ch1 == ')' || ch2 == '{' && ch1 == '}' || ch2 == '[' && ch1 == ']') {
                    stack.pop();
                } else {
                    return false;
                }
            }
        }
        return stack.empty();
    }

    public boolean IsPopOrder(int[] pushV, int[] popV) {
        Stack<Integer> stack = new Stack<>();
        int j = 0;
        for (int i = 0; i < pushV.length; i++) {
            stack.push(pushV[i]);
            while (!stack.empty() && j < popV.length && stack.peek() == popV[j]) {
                j++;
                stack.pop();
            }
        }
        return stack.empty();
    }



}
